﻿using Md.Api.DDD;
using Md.Api.Model.Web.MdUser.Request;
using Md.Redis.Repositories;

namespace Md.Api.Service.Web.MdUser;
/// <summary>
/// 发送邮箱验证码服务
/// </summary>
public class SendEmailVerificationCodeService : ApiBase<RequestSendEmailVerificationCodeModel>
{
    /// <summary>
    /// redis缓存
    /// </summary>
    public MdRedisService _redisService { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var ran = new Random();

        var code = ran.Next(100000, 999999);

        var res = EmailHelp.SendEmail(JsonConfig.JsonRead("MdEmail:AuthEmail"), Parameter.Email, "KOLfinds", $"Verification Code：{code}");

        var uuid = Guid.NewGuid().ToString();

        _redisService.Instance.Set(uuid, code, 60);

        Result.Data = new { uuid, res };
    }
}

